
<style>
.custom-switch {
    padding-left: 3.25rem;
}
.custom-control {
    position: relative;
    display: block;
    min-height: 1.5rem;
    padding-left: 2.5rem;
}
.custom-control-input {
    position: absolute;
    z-index: -1;
    opacity: 0;
}
.custom-control-label {
    position: relative;
    margin-bottom: 0;
    vertical-align: top;
}
.custom-switch .custom-control-label::before {
    left: -3.25rem;
    width: 1.75rem;
    pointer-events: all;
    border-radius: .5rem;
}
.custom-control-label::before {
    position: absolute;
    top: .25rem;
    left: -2.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    pointer-events: none;
    content: "";
    background-color: #dee2e6;
    border: #adb5bd solid 1px;
    box-shadow: inset 0 0.25rem 0.25rem rgba(0,0,0,.1);
}
.custom-control-label::before, .custom-file-label, .custom-select {
    transition: background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.custom-switch .custom-control-label::after {
    top: calc(.25rem + 2px);
    left: calc(-3.25rem + 2px);
    width: calc(1rem - 4px);
    height: calc(1rem - 4px);
    background-color: #adb5bd;
    border-radius: .5rem;
    transition: background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out,-webkit-transform .15s ease-in-out;
    transition: transform .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
    transition: transform .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out,-webkit-transform .15s ease-in-out;
}
.custom-control-input:checked~.custom-control-label::before {
    color: #fff;
    border-color: #007bff;
    background: #007bff linear-gradient(180deg,#268fff,#007bff) repeat-x;
    box-shadow: none;
}
.custom-switch .custom-control-input:checked~.custom-control-label::after {
    background-color: #dee2e6;
    -webkit-transform: translateX(.75rem);
    transform: translateX(.75rem);
}
.custom-control-label::after {
    position: absolute;
    top: .25rem;
    left: -2.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    content: "";
    background: no-repeat 50%/50% 50%;
}

.filter .title-h{font-size:14px;border-bottom:1px solid #dcdcdc;padding-bottom:10px}.filter dl{position:relative;margin-bottom:10px}.filter dl:after{content:"";display:block;clear:both}.filter dl dt{position:absolute;top:0;left:0;font-weight:700}.filter dl dd{padding-left:100px}.filter dl dd a{margin-right:20px;margin-bottom:10px;display:inline-block}.filter dl dd a.on{font-weight:700;color:#477fd2}

.shiprow,.shiplb{cursor:pointer;}
</style>
<div class="row">
                        <div class="col-sm-12">
                             <div class="box">
                                <div class="box-header with-border">

                                    <div class="pull-right" style="padding:5px 8px;">
                                    <?php echo '共'.$total.'条记录，'.$page.'/'.$pages.'页';?>
                                    </div>
                                    
                                    <div class=" col-sm-6">
                                    <?php echo form_open(current_url(), array('class' => 'form-inline', 'method'=>'get', 'id' => 'search_goods')); ?>                                    
                                    <div class="form-group" style="margin-right:15px;">
                                    <select class="form-control" name="state">
                                        <option value="0">所有状态</option>
                                        <?php foreach($statetype as $k=>$s):?>
                                        <option value="<?php echo $k+1;?>" <?php if(($k+1)==$state) echo " selected";?>><?php echo $s;?></option>
                                        <?php endforeach;?>
                                    </select>
                                    </div>

                                    <div class="form-group" style="margin-right:15px;">
                                    <?php echo form_input($keyword);?>
                                    </div>

                                    
                                    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-sm btn-primary btn-flat', 'content' => "搜索物流")); ?>
                                    
                                    
                                    <?php echo form_close();?>
                                    </div>

                                    
                                </div>


                                           
<div class="filter">
<div class="box-body" style="padding-left:25px;margin-top:20px;">

<dl>
<dt>排序</dt>
<dd>
<a href="" onclick="return filter('sort','paytime_desc');"  rel="" name="stage" class="all<?php if($sort=='paytime_desc') echo ' on';?>">付款时间</a>
<a href="" onclick="return filter('sort','disputetime_asc');"  rel="" name="stage" class="sx_child<?php if($sort=='disputetime_asc') echo ' on';?>">结束时间</a>
</dd>
</dl>
</div>
</div>
<?php
$olist=[];
?>

                                <div class="box-body" style="margin-top:20px;">
                                <table class="table table-bordered table-striped dataTable">
							<tr>
								<th>ID</th>                
								<th width="100">订单号</th>  
                                <th>价格</th>    
								<th width="450">Last Track</th>
								<th>物流类型</th>
								<th>物流单号</th>								
                                <th>状态</th>
                                <th>妥投</th>
                                <th>争议</th>
                                <th>重购</th>                            
								<th>付款时间</th>      
								<th>结束时间</th>         
								<th>更新时间</th>
                                <th>备注</th>
							</tr>
							<?php 
							foreach($data as $item){
							 ?>
							 <tr>
							 <td><?php echo $item["id"];?></td>
							 <td><a href="/backend/orders?keyword=<?php echo $item["ordersn"];?>" target="_blank"><?php echo $item["ordersn"];?></a></td>
                             <td><?php echo $item["price"]>0?"$".$item["price"]:"";?></td>
							 <td>
                                <?php
                                $track=json_decode($item["tracklog"],true);
                                if(!$track && !isset($track["detailList"]) || count($track["detailList"])==0)
                                {
                                    echo "no event";
                                }
                                else
                                {
                                    echo '<div class="shiprow">';

                                    echo ("<b>".date("m-d H:i",strtotime($track["detailList"][0]["date"]." ".$track["detailList"][0]["time"]))."</b> ".$track["detailList"][0]["desc"]);
                                    echo '</div>';


                                    ?>

                                    <div class="shiplb"  style="display:none;">
                                    <?php
                                        
                                            foreach($track["detailList"] as $re)
                                            {
                                                echo "<div><b>".date("m-d H:i",strtotime($re["date"]." ".$re["time"]))."</b> ".$re["desc"]."</div>";
                                            }                                     

                                    ?>
                                    </div>

                                    <?php
                                }
                                ?>
                             </td>	
							 <td><?php echo $item["shiptype"];?></td>
                             <td><?php 
                             $olist[]=$item["shipnum"];
                             $link="https://global.cainiao.com/detail.htm?mailNoList=".$item["shipnum"]."&spm=a3708.7860688.0.d01&lang=en";
                             echo '<a href="'.$link.'" target="_blank">'.$item["shipnum"].'</a>';?> <a href=" https://t.17track.net/en#nums=<?php echo $item["shipnum"];?>" target="_blank">17track</a> </td>
                             <td><span class="label <?php echo $statelabel[$item["status"]]; ?>"><?php echo $statetype[$item["status"]]; ?></span></td>	
                             <td>
                             <div class="custom-control custom-switch" style="margin-left:10px;" cid="<?php echo $item["id"];?>">
        <input type="checkbox" class="custom-control-input syncbox" id="toogle<?php echo $item["id"];?>" <?php if($item["status"]==1) echo " checked";?>>
        <label class="custom-control-label" for="toogle<?php echo $item["id"];?>"></label>
    </div>

                             </td>

                             <td>
    <div class="custom-control custom-switch" style="margin-left:10px;" cid="<?php echo $item["id"];?>">
        <input type="checkbox" class="custom-control-input manbox" id="mtoogle<?php echo $item["id"];?>" <?php if($item["status"]==2) echo " checked";?>>
        <label class="custom-control-label" for="mtoogle<?php echo $item["id"];?>"></label>
    </div>

    </td>

    <td>
    <div class="custom-control custom-switch" style="margin-left:10px;" cid="<?php echo $item["id"];?>">
        <input type="checkbox" class="custom-control-input rebuy" id="ctoogle<?php echo $item["id"];?>" <?php if($item["status"]==3) echo " checked";?>>
        <label class="custom-control-label" for="ctoogle<?php echo $item["id"];?>"></label>
    </div>

    </td>


							 <td><?php echo date("m-d h:i",strtotime($item["paytime"]));?></td>
                             
                            
                             <td><?php echo friendlyDatemore(strtotime($item["disputetime"])); //echo friendlyDatemore(strtotime($item["disputetime"]));?>

							 <td><?php echo date("m-d h:i",strtotime($item["updatetime"]));?></td>
											 
                             <td shopid="<?php echo $item["id"];?>"><span ondblclick="edit(this,'memo');" <?php if($item["memo"]) echo 'style="color:red;"';?>><?php echo $item["memo"]?htmlentities($item["memo"]):"双击添加备注"; ?></span></td>

							 </tr>
							 <?php    
							 }							
							 ?>
						</table>
						
						<?php echo $pager;?>

                        <div class="row pull-right" style="margin-top:16px;"><a href="https://t.17track.net/zh-cn#nums=<?php echo implode(",",$olist);?>"  target="_blank" class="btn btn-flat btn-info">查询所有17Track</a> <a href="https://global.cainiao.com/detail.htm?mailNoList=<?php echo implode("%2C",$olist);?>&spm=a3708.7860688.0.d01" target="_blank"  class="btn btn-flat btn-success">查询所有菜鸟</a></div>
                                </div>
                            </div>
                         </div>
                    </div>

                    

<script>



$("input.syncbox").on("click",function(){
    var cid = $(this).parent().attr("cid");     
    if($(this).is(":checked"))
    {
        newval=1;
    }
    else
    {
        newval=0;
    }
    $.ajax({
        type:"post",
        url:"/backend/alishipment/ajaxedit",
        dataType:"json",
        data:{"attrName":"status","newHtml":newval,"cid":cid},
        error:function(){
        },
        success:function(){
        },
    });
});

$("input.manbox").on("click",function(){
    var cid = $(this).parent().attr("cid");     
    if($(this).is(":checked"))
    {
        newval=2;
    }
    else
    {
        newval=0;
    }
    $.ajax({
        type:"post",
        url:"/backend/alishipment/ajaxedit",
        dataType:"json",
        data:{"attrName":"status","newHtml":newval,"cid":cid},
        error:function(){
        },
        success:function(){
        },
    });
});


$("input.rebuy").on("click",function(){
    var cid = $(this).parent().attr("cid");     
    if($(this).is(":checked"))
    {
        newval=3;
    }
    else
    {
        newval=0;
    }
    $.ajax({
        type:"post",
        url:"/backend/alishipment/ajaxedit",
        dataType:"json",
        data:{"attrName":"status","newHtml":newval,"cid":cid},
        error:function(){
        },
        success:function(){
        },
    });
});



function edit(obj,attrName){
    var oldHtml = obj.innerHTML;
    var hint = '';
    if(oldHtml=="双击添加备注")
    {
        hint = oldHtml;
        oldHtml = '';
    }
    var newobj = document.createElement('input');
    newobj.name = attrName;
    newobj.type = "text";
    newobj.setAttribute("class","form-control input-sm");
    newobj.value = oldHtml;
    var cid = $(obj).parent().attr("shopid");     
    obj.innerHTML = '';  
    obj.appendChild(newobj);
    newobj.focus(); 

    $(newobj).keydown(function (event) {
        if (event.keyCode == 13) {
            $(this).trigger("blur");
        }
    });

    $(newobj).blur(function(){
        if(this.value==null || this.value==""){
            if(hint)
            {
                obj.innerHTML = hint;
            }
            else
            {
                obj.innerHTML = oldHtml;
            }
            
            return false;
        }
        obj.innerHTML = this.value?this.value:oldHtml;       
        if(oldHtml != this.value){
            $.ajax({
                type:"post",
                url:"/backend/alishipment/ajaxedit",
                dataType:"json",
                data:{"attrName":attrName,"newHtml":this.value,"cid":cid},
                error:function(){
                },
                success:function(){
                },
            });
        }  

    })
}


function changeURLArg(url, arg, arg_val) {
        var pattern = arg + '=([^&]*)';
        var replaceText = arg + '=' + arg_val;
        if (url.match(pattern)) {
            var tmp = '/(' + arg + '=)([^&]*)/gi';
            tmp = url.replace(eval(tmp), replaceText);
            return tmp;
        } else {
            if (url.match('[\?]')) {
                return url + '&' + replaceText;
            } else {
                return url + '?' + replaceText;
            }
        }
        return url + '\n' + arg + '\n' + arg_val;
    }

    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); 
        var r = window.location.search.substr(1).match(reg); 
        if (r != null) return unescape(r[2]); return null;
    }

    function layerConfirm(msg, t) {
        layer.confirm(msg, function (index) {
            t.onclick = "";
            t.click();
            layer.close(index);
        });
    }

    function filter(name,val)
    {
        if(getUrlParam(name)==val){
            return false;
        }
        var url= window.location.href;
        var newUrl=  changeURLArg(url, name, val); 
        window.location.href =  newUrl;
        return false;
    }

    $("div.shiprow").on("click",function(){
        $(this).toggle();
        $(this).parent().find("div.shiplb").toggle();
    });
    $("div.shiplb").on("click",function(){
        $(this).toggle();
        $(this).parent().find("div.shiprow").toggle();
    })
</script>
